using System;

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace CreateLabelExample
{
    class Program
    {
        static void Main(string[] args1)
        {
            string[] args = new string[3];

            args[0] = "ffm-srv-tfs-1";
            args[1] = "MyLabel_1";
            args[2] = "$/TestOL50Komplett";
            // args[2] = "$/TestOL50Komplett/OL50_BuildResults.mdb";

            if (args.Length < 3)
            {
                Console.Error.WriteLine("Argument ist nicht optional!");
                Environment.Exit(1);
            }
            string serverName = args[0];
            string labelName = args[1];

            TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(serverName);
            VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));

            // What label do we want to construct?
            string labelOwner = vcs.AuthenticatedUser;
            string labelScope = "$/TestOL50Komplett";
            string labelComment = "Ich bin ein Testlabel!";
            VersionControlLabel labelToCreate = new VersionControlLabel(vcs, 
                                                                        labelName,
                                                                        labelOwner,
                                                                        labelScope,
                                                                        labelComment);

            // zu labelnde items
            LabelItemSpec[] labelItemSpecs = new LabelItemSpec[args.Length - 2];
            for (int i = 2; i < args.Length; i++)
			{
                
                ItemSpec itemSpec = new ItemSpec(args[i], RecursionType.None);
                
                labelItemSpecs[i-2] = new LabelItemSpec(itemSpec, VersionSpec.Latest, false);

			}

            vcs.CreateLabel(labelToCreate, labelItemSpecs, LabelChildOption.Replace);

            Console.WriteLine("Label erfolgreich erstellt: {0}", labelToCreate.Name);
        }
    }
}
